<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@include file="./common/header.jsp" %>
<head>
	<style type="text/css">
		PRE {
			padding-top: 0px;
			padding-bottom: 0px;
			padding-left: 60px;
			padding-right: 10px;
			border-right: #cccccc 1px dashed;
			border-bottom: #cccccc 1px dashed;
			border-top: #cccccc 1px dashed;
			border-left-width: 0px;
			background:#fafafa url(images/codebg.jpg) repeat-y fixed 0 0;
			color: #4d87ce;
		}
		#comment_form_id td{
			padding-left: 25px;
			padding-bottom:10px;
		}
		
	</style>
</head>
<body>
<%@ include file="./common/top.jsp"%>
	
	<div id="mainContainer" class="container">
		<form id="comment_form_id" name="comment_form">
			<table>
			
				<tr class="username-tr">
					<td width="120px" > <label class="control-label" >用户名称</label></td>
					<td>
						<input name="comment.username" id="username"  style="width: 100px;" type="text" class=" required" />
					</td>
					
					<td width="120px" > <label class="control-label" >评论时间</label></td>
					<td>
						<input name="updateDate" id="updateDate" style="width:150px;" type="text" class=" required" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})" placeholder="选择时间"/>
					</td>
					
					<td width="120px" > <label class="control-label" >星级(1-5)</label></td>
					<td>
						<input name="comment.grade" id="grade" style="width:50px" type="text" class=" required validate-number max-value-5 min-value-1" value="5"/>
					</td>
				</tr>
			
				<tr class="content-tr">
					<td width="120px" > <label class="control-label" >内容</label></td>
					<td colspan="8">
						<textarea name="comment.content" id="content" style="height:50px;width: 600px; "></textarea>
					</td>
				</tr>
				
				<tr>
					<td>&nbsp;
						<input type="hidden" name="comment.id" id="commentId"/>
					</td>
					<td align="left"><input type="button" id="edit_comment_btn_id" value="修改" class="btn btn-primary"
						style="margin-top: 15px" /></td>
				</tr>
			</table>
		</form>
	</div>
	<script>
		
		$(function(){
			var commentId =$.request.queryString["id"];
			var goodsId =$.request.queryString["goodsId"];
			$("#commentId").val(commentId);
			
			$("#mainContainer").showLoading();
			jQuery.ajax({
				type : 'Get',
				contentType : 'application/json',
				url : '../admin/comment/get.do',
				data : {
					id:commentId
				},
				dataType : 'json',
				success : function(data) {
					if (data.result) {
						var vo = data.obj;
						$("#username").val(vo.comment.username);    
						$("#content").val(vo.comment.content);     
						$("#grade").val(vo.comment.grade);     
						$("#updateDate").val(vo.updateDate);     
					} else {
						alert('数据库异常,查询数据失败');
					}
					$("#mainContainer").hideLoading();
				},
				error : function(data) {
					
				}
			});	
			
			var valid = new jValidation.Validation('comment_form_id',{immediate:true},{onSubmit:false});
			$('#edit_comment_btn_id').click(
				function(){
					var result = valid.validate();
					if(!result){
						return;
					}
					var formData = $('#comment_form_id').serialize();
					jQuery.ajax( {
						type : 'POST',
						url : '../admin/comment/edit.do',
						dataType : 'json',
						data : formData,
						success : function(obj) {
							if(obj.result){
								alert("修改成功");
								location.href = "./commentList.jsp?id="+goodsId;
							}else{
								alert(obj.errorMsg);
							}
						},
						error : function() {
							alert('error');
						}
					});
				}		
			);
		});
		
		
	</script>
</body>
</html>
